package cn.itzzx.resume.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * TODO
 *
 * @author Martin
 * @since 1.0
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //resume-springboot
        String contextPath = request.getContextPath();
        String requestURI = request.getRequestURI();
        System.out.println(requestURI);
        String data = (String) request.getSession().getAttribute("user");
        if (data == null) {
            //http://localhost:8080/resume-springboot
            response.sendRedirect(contextPath);
            return false;
        }
        return true;
    }
}
